package cn.lf.android.lawfirm.distribution.controller;


import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.lf.android.lawfirm.AppConfig;
import cn.lf.android.lawfirm.BaseController;
import cn.lf.android.lawfirm.distribution.modle.Distribution;
import cn.lf.android.lawfirm.distribution.modle.DistributionInfo;
import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.undertake.apply.modle.UndertakeApply;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.JsonBeans;
import cn.lf.android.lawfirm.utils.SPUtil;

public class DistributionInfoConroller extends BaseController {
    DistributionInfoCallback mDistributionInfoCallback;
    private Context context;

    public DistributionInfoConroller(DistributionInfoCallback callback, Context context) {
        this.mDistributionInfoCallback = callback;
        this.context = context;
    }

    /**
     * 案源分派信息
     *
     * @param caseId
     */
    public void onDistributInfo(String caseId) {
        showProgressDia(context);
        Map<String, String> params = new HashMap<String, String>();
        SPUtil spUtil = new SPUtil(context);
        params.put("caseId", caseId);
        DebugLog.e("caseId==" + caseId);
        new MyOkHttpClient().doGet(AppConfig.CaseInfo_AssignIni, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("案源分派信息==" + response);
                        JSONObject myJsonObject;
                        JSONObject responsObject;
                        Boolean isSuc;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                responsObject = myJsonObject.getJSONObject("responsObject");
                                DistributionInfo beans = JSON.parseObject(responsObject.toString(), DistributionInfo.class);
                                mDistributionInfoCallback.onDistributionInfoSuccessed(beans);
                            } else {
                                mDistributionInfoCallback
                                        .onDistributionInfoFailed();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        dismissProgressDia();
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        mDistributionInfoCallback.onDistributionInfoFailed();
                        dismissProgressDia();
                    }
                }, "Authorization", spUtil.getAccessToken());
    }



    public interface DistributionInfoCallback {
        public void onDistributionInfoSuccessed(DistributionInfo beans);

        public void onDistributionInfoFailed();

    }

}
